function getCookie(key) {
    // 获取所有的cookie  document.cookie
    let cookie = document.cookie;//"username=zhangsan; password=123456"
    let arr = cookie.split('; '); //['username=zhangsan','password=123456']
    // 遍历arr
    for (let i = 0; i < arr.length; i++) { //每一项'username=zhangsan'
        //    每一项（arr[i]='username=zhangsan'）再次分割
        let item = arr[i].split('=');
        //   item[0]代表键  item[1]代表值
        if (item[0] == key) {
            return item[1];
        }
    }
    return '';
}
function setCookie(key, value, day) {
    let date = new Date();
    date.setDate(date.getDate() + day)
    document.cookie = key + '=' + value + ';expires=' + date;
}
//删除cookie
function delCookie(key) {
    setCookie(key, " ", -1);
}